Skip to content

feat: implement event-driven architecture with Kafka, idempotency, and Redis integration#616

Open
cpulachev8 wants to merge 4 commits intoyaperos:mainfrom
cpulachev8:feature/code-challenge
Open

feat: implement event-driven architecture with Kafka, idempotency, and Redis integration#616
cpulachev8 wants to merge 4 commits intoyaperos:mainfrom
cpulachev8:feature/code-challenge

Conversation

@cpulachev8
Copy link
Copy Markdown

🚀 Overview

This PR implements a transaction processing system using an event-driven architecture.

The solution introduces asynchronous communication between services using Kafka, ensuring decoupling, scalability, and resilience.


🧩 Architecture

  • Transaction Service publishes events when a transaction is created
  • Anti-Fraud Service consumes events and evaluates transactions
  • Transaction status is updated asynchronously based on the validation result

⚙️ Key Features

Event-Driven Architecture

  • Implemented using Kafka for asynchronous communication
  • Decouples transaction processing from fraud validation

Idempotency

  • HTTP layer: uses Idempotency-Key to prevent duplicate transactions
  • Consumer layer: prevents duplicate event processing using Redis

Redis Integration

  • Used for:

    • Idempotency key storage
    • Deduplication of Kafka events
  • TTL applied to avoid unbounded growth

Transaction Lifecycle

  • PENDINGAPPROVED | REJECTED

🛠️ Tech Stack

  • Node.js (NestJS)
  • Kafka (event streaming)
  • Redis (idempotency + deduplication)
  • PostgreSQL (persistence)

🧪 How to Test

  1. Start services:
docker-compose up -d
  1. Run both services

  2. Create a transaction:

POST /transactions
Header: Idempotency-Key: <unique-key>
  1. Verify:
  • Transaction is created with PENDING
  • Anti-fraud processes event
  • Status updates to APPROVED or REJECTED

📌 Notes

  • System is eventually consistent
  • Designed to handle service failures (Kafka retains events)
  • Idempotency ensures safe retries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant